#include <avr/io.h>

#ifndef F_CPU
#define F_CPU 8000000UL
#endif

//set desired baud rate
#define BAUDRATE 19200

//calculate UBRR value
#define UBRRVAL ((F_CPU/(BAUDRATE*16UL))-1)


void USART_Init();
void rsprint(int8_t *buf);


void USART_Init()
{
	//Set baud rate
	UBRRL=UBRRVAL; //low byte
	UBRRH=(UBRRVAL>>8); //high byte
	//Set data frame format: asynchronous mode,no parity, 1 stop bit, 8 bit size
	UCSRC=(1<<URSEL)|(0<<UMSEL)|(0<<UPM1)|(0<<UPM0)|(0<<USBS)|(0<<UCSZ2)|(1<<UCSZ1)|(1<<UCSZ0);
	//Enable Transmitter and Receiver
	UCSRB=1<<TXEN;
}


void rsprint(int8_t *buf)
{
	while (*buf)
	{
	  if ( UCSRA&(_BV(UDRE)) )
	  {
		UDR=*buf++;	
 	  };
    }
}
